

import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBFindModel/YBFindModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBWorkTaiNetWork/YBBaseWorkTaiNetWorkManager.dart';

class YBFindMainProvider with ChangeNotifier {

  List<YBFindModel> _findList = List<YBFindModel>();

  List<YBFindModel> get findModelList => _findList;

  RefreshController _easyRefreshController = RefreshController();

  RefreshController get easyRefreshController => _easyRefreshController;

  int _currentPage = 1;

  Future refreshData(String tagCode) async {
    _currentPage = 1;
    getFindDataList(_currentPage, tagCode);
  }

  Future loadData(String tagCode) async {
    _currentPage++;
    getFindDataList(_currentPage, tagCode);
  }

  Future getFindDataList(int page,String tagCode) async {
    YBBaseWorkTaiNetWork.workTaiGongGaoArticleList({
      "sysCode":"xg_youbang",
      "tagCode":tagCode,
      "pageSize":20,
      "pageNo":page,
    },success:(data){
      print("----$data----");
      _easyRefreshController.loadComplete();
      _easyRefreshController.refreshCompleted();
      int totalPage = data['totalPage'];
      if (totalPage == page) {
        _easyRefreshController.refreshCompleted();
      }
      List resultList = data['result'];
      if (!ObjectUtil.isEmptyList(resultList)) {
        _findList.addAll(resultList.map((e){
          return YBFindModel.fromjson(e);
        }).toList());
        print('--发现信息-$_findList--');
        notifyListeners();
      }
    },fail: (error){
      _easyRefreshController.refreshCompleted();
    });
  }

}
